// /** 游戏数据 */

import { _decorator, Vec2 } from 'cc';
import TurkishTetris_CardGroup from "../../game/Script/XXL/Game/TurkishTetris_CardGroup";
import TurkishTetris_GameConfig from "./TurkishTetris_GameConfig";
import { TurkishTetris_GameStorage } from "./TurkishTetris_GameStorage";

export class TurkishTetris_GameData {
    //    /** 卡牌组 CardGroup */
    static arrCardGroups: TurkishTetris_CardGroup[][] = [];
    //    /** 卡牌组最下面一行准备行 CardGroup */
    static arrCardGroups_next: TurkishTetris_CardGroup[] = [];
    //    /** 卡牌 */
    static arrCards: any[][] = [];
    //    /** 地形格子 XXL_Grid */
    static arrGrids: any[][] = [];
    //    /** StartPos */
    static StartPos: Vec2;
    //    /** CurrentPos */
    static CurrentPos: Vec2;
    //    /** IsMouseDown  */
    static IsMouseDown: boolean = false;
    //    /** 是否可以操作 */
    static IsCanOperate: boolean = true;
    static hasNewLine: boolean = false;
    //    // 连消数量
    static ContinuousEliminationNumber: number = 0;
    //    /** 最少行数 */
    static MinRowNumber: number = 2;
    static high_score: number = 0;
    // static curScore: number = 0;
    static gameMode = 0; // 0普通模式 1冒险模式
    static desertGameUseTime: number = 0;
    static InitData() {
        TurkishTetris_GameData.arrGrids = [];
        TurkishTetris_GameData.arrCards = [];

        TurkishTetris_GameData.arrCardGroups = [];
        TurkishTetris_GameData.arrCardGroups_next = [];

        TurkishTetris_GameData.IsCanOperate = true;

        TurkishTetris_GameData.ContinuousEliminationNumber = 0;
        TurkishTetris_GameData.MinRowNumber = 2;

        // TurkishTetris_GameData.curScore = 0;

        // GameStorage.data.high_score_lastTime = GameStorage.data.high_score;

        TurkishTetris_GameData.desertGameUseTime = 0;
    }

    static GetScore() {
        return TurkishTetris_GameStorage.data.score;
    }
    static SetScore(value) {
        TurkishTetris_GameStorage.data.score = value;
        TurkishTetris_GameStorage.saveData();
    }

    static GetLevel() {
        return 0;
        // return TurkishTetris_GameStorage.data.GameData.level;
    }
    // static SetLevel(value) {
    //     TurkishTetris_GameStorage.data.GameData.level = value;
    //     TurkishTetris_GameStorage.saveData();
    // }
    //    // 刷新后，但是行数不满足min(等级+1，6），则通过保底刷新的方式，将方块行数补全到指定行数。
    static GetMinRowNumber() {
        let number = TurkishTetris_GameData.GetLevel() + 1 + 1;
        TurkishTetris_GameData.MinRowNumber = number < 6 ? number : 6;
        return TurkishTetris_GameData.MinRowNumber;
    }
    //    /** 是否死亡 */
    static IsDead() {
        if (TurkishTetris_GameData.arrCardGroups[TurkishTetris_GameConfig.row - 1].length > 0) {
            // if (GameData.arrCardGroups[3].length > 0) {
            return true;
        }

        return false;
    }
    //    /** 是否在新手引导 */
    static IsNewGuide() {
        if (TurkishTetris_GameStorage.data.guideStep < 2) {
            return true;
        }

        return false;
    }
    static ClearData() {
        TurkishTetris_GameData.arrGrids = [];
        TurkishTetris_GameData.arrCards = [];

        TurkishTetris_GameData.arrCardGroups = [];
        TurkishTetris_GameData.arrCardGroups_next = [];

        TurkishTetris_GameData.ContinuousEliminationNumber = 0;
        TurkishTetris_GameData.MinRowNumber = 2;

        // TurkishTetris_GameData.curScore = 0;
        TurkishTetris_GameData.SetScore(0);

        TurkishTetris_GameData.StartPos = null;
        TurkishTetris_GameData.CurrentPos = null;
        TurkishTetris_GameData.IsMouseDown = false;

        TurkishTetris_GameData.IsCanOperate = true;

        TurkishTetris_GameData.desertGameUseTime = 0;
    }
}

window["TurkishTetris_GameData"] = TurkishTetris_GameData;